package com.bitejiuyeke.forum.controller;

import com.bitejiuyeke.forum.common.AppResult;
import com.bitejiuyeke.forum.exception.ApplicationException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 比特就业课
 */
@Api(tags = "测试接口")
@Slf4j // 日志
@RestController // 表示在BODY中返回数据
@RequestMapping("/test") // 一级映射路径
public class TestController {

    @ApiOperation("Hello 测试")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring boot...";
    }

    @ApiOperation("Hello 测试(带参数)")
    @GetMapping("/helloByName")
    public AppResult helloByName (@ApiParam("名字") String name) {
        return AppResult.success("你好：" + name);
    }

    @ApiOperation("异常测试")
    @GetMapping("/exception")
    public AppResult testException () throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("自定义异常测试")
    @GetMapping("/appException")
    public AppResult testApplicationException () {
        throw new ApplicationException("这是一个ApplicationException...");
    }
}
